{
    //角色骨骼动画，无计算逻辑
    class Hero extends Laya.Sprite {
        constructor(name) {
            super();
            //角色名字(给子类使用)
            this._name = name;
            this._face = 1;
            this._aniName = null;
            this.isAttack = false;
            this.create();
        }

        create() {
            this.pos(40, 150);
            this.roleAni = Sail.Utils.createSkeleton('res/game/role/' + this._name);
            // this.roleAni.pos(90, 300);
            this.addChild(this.roleAni);

            //武器骨骼
            this.weaponAni = Sail.Utils.createSkeleton('res/game/role/' + this._name + '_weapon');
            this.weaponAni.pos(0, -20);
            this.roleAni.addChild(this.weaponAni);

            //开火动画
            this.sparkAni = Sail.Utils.createSkeleton('res/game/role/spark');
            this.sparkAni.pos(45, -10);
            this.weaponAni.addChild(this.sparkAni);

            //开火结束后
            this.weaponAni.on('stopped', this, () => { this.stopAttack(); this.event('attack_end');});
            this.roleAni.on('stopped', this, () => { this.play('standby'); this.event('act_end'); });

            //播放待机
            this.play('standby');
        }

        //角色脸的朝向
        setFace(v) {
            this.roleAni.scaleX = v;
            this._face = v;
        }

        getFace() {
            return this._face;
        }

        //播放动画(开火特殊处理，人物不播放)
        play(d, loop = true) {
            this._aniName = d;
            this.roleAni.play(d, loop, false);
            if (!this.isAttack) {
                this.weaponAni.play(d, loop, false);
            }
        }

        stopAttack() {
            this.isAttack = false;
            this.roleAni.play(this._aniName, true, true);
            this.weaponAni.play(this._aniName, true, true);
            this.resetWeaponRotation();  
        }

        //播放攻击动画
        attack(hasSpark = true) {
            this.isAttack = true;
            this.weaponAni.play('attack', false);

            //是否播放开火动画(有些攻击方式不播放)
            if (hasSpark) {
                this.sparkAni.play(0, false);
            }
        }

        resetWeaponRotation(){
            this.weaponAni.rotation = 0;
        }

        //控制武器的转向
        changeWeaponRotation(angle) {
            this.weaponAni.rotation = this.roleAni.scaleX == 1 ? angle : -angle + 180;
        }

    }

    Sail.class(Hero, "Hero.Base");
}